/*
 * GridResourceJPanel.java
 *
 * Created on Utorok, 2007, november 6, 14:07
 */

package gui;

import java.util.Vector;
import javax.swing.event.CellEditorListener;
import javax.swing.event.ChangeEvent;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import logic.gridNodes.GridResource;

/**
 *
 * @author  handsome
 */
public class GridResourceJPanel extends ParametersPanel 
    implements CellEditorListener{

    GridResource Resource = null;
    /** Creates new form GridResourceJPanel */
    public GridResourceJPanel() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        NameJLbl = new javax.swing.JLabel();
        NameJTxtField = new javax.swing.JTextField();
        PeakLoadJLbl = new javax.swing.JLabel();
        OffPeakLoadJLbl = new javax.swing.JLabel();
        HolidayJLbl = new javax.swing.JLabel();
        PeakLoadJSld = new javax.swing.JSlider();
        OffPeakLoadJSld = new javax.swing.JSlider();
        HolidayLoadJSld = new javax.swing.JSlider();
        TimeZoneJLbl = new javax.swing.JLabel();
        CostPSecJLbl = new javax.swing.JLabel();
        OSJLbl = new javax.swing.JLabel();
        ArchitectJLbl = new javax.swing.JLabel();
        TimeZoneJTxtField = new javax.swing.JTextField();
        CostJTxtField = new javax.swing.JTextField();
        OSJTxtField = new javax.swing.JTextField();
        ArchitectJTxtField = new javax.swing.JTextField();
        ProcJLbl = new javax.swing.JLabel();
        CountProcJLbl = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        TablejTbl = new javax.swing.JTable();
        ProcCountjTxtField = new javax.swing.JTextField();
        ConfirmjLbl = new javax.swing.JLabel();

        setMinimumSize(new java.awt.Dimension(320, 650));
        NameJLbl.setText("Name :");

        NameJTxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                NameJTxtFieldActionPerformed(evt);
            }
        });
        NameJTxtField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                NameJTxtFieldFocusLost(evt);
            }
        });

        PeakLoadJLbl.setText("Peak Load :");

        OffPeakLoadJLbl.setText("Off-peak Load :");

        HolidayJLbl.setText("Holiady Load :");

        PeakLoadJSld.setMaximum(99);
        PeakLoadJSld.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                PeakLoadJSldMouseReleased(evt);
            }
        });

        OffPeakLoadJSld.setMaximum(99);
        OffPeakLoadJSld.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                OffPeakLoadJSldMouseReleased(evt);
            }
        });

        HolidayLoadJSld.setMaximum(99);
        HolidayLoadJSld.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                HolidayLoadJSldMouseReleased(evt);
            }
        });

        TimeZoneJLbl.setText("Time Zone :");

        CostPSecJLbl.setText("Costs per sec. :");

        OSJLbl.setText("Operating System :");

        ArchitectJLbl.setText("Architecture :");

        TimeZoneJTxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TimeZoneJTxtFieldActionPerformed(evt);
            }
        });
        TimeZoneJTxtField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                TimeZoneJTxtFieldFocusLost(evt);
            }
        });

        CostJTxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CostJTxtFieldActionPerformed(evt);
            }
        });
        CostJTxtField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                CostJTxtFieldFocusLost(evt);
            }
        });

        OSJTxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OSJTxtFieldActionPerformed(evt);
            }
        });
        OSJTxtField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                OSJTxtFieldFocusLost(evt);
            }
        });

        ArchitectJTxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ArchitectJTxtFieldActionPerformed(evt);
            }
        });
        ArchitectJTxtField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                ArchitectJTxtFieldFocusLost(evt);
            }
        });

        ProcJLbl.setText("Processors :");

        CountProcJLbl.setText("count ");

        jScrollPane1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jScrollPane1FocusLost(evt);
            }
        });

        TablejTbl.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        TablejTbl.setRowSelectionAllowed(false);
        TablejTbl.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                TablejTblFocusLost(evt);
            }
        });

        jScrollPane1.setViewportView(TablejTbl);

        ProcCountjTxtField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ProcCountjTxtFieldActionPerformed(evt);
            }
        });
        ProcCountjTxtField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                ProcCountjTxtFieldFocusLost(evt);
            }
        });

        ConfirmjLbl.setText("<html><i> To confirm press Enter</i></html>");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(OffPeakLoadJLbl)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(OffPeakLoadJSld, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(NameJLbl)
                                .addComponent(PeakLoadJLbl))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(PeakLoadJSld, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(12, 12, 12)
                                    .addComponent(NameJTxtField, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(HolidayJLbl)
                                .addComponent(TimeZoneJLbl)
                                .addComponent(OSJLbl)
                                .addComponent(CostPSecJLbl)
                                .addComponent(ArchitectJLbl)
                                .addComponent(ProcJLbl))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(HolidayLoadJSld, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addGap(12, 12, 12)
                                        .addComponent(CountProcJLbl)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ProcCountjTxtField))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                        .addGap(13, 13, 13)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(OSJTxtField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(ArchitectJTxtField, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(TimeZoneJTxtField, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(CostJTxtField, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))))))))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ConfirmjLbl))
                .addContainerGap(21, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(NameJTxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(NameJLbl))
                .addGap(16, 16, 16)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(PeakLoadJSld, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(PeakLoadJLbl))
                .addGap(17, 17, 17)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(OffPeakLoadJSld, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(OffPeakLoadJLbl))
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(HolidayLoadJSld, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(HolidayJLbl))
                .addGap(36, 36, 36)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(TimeZoneJLbl)
                            .addComponent(TimeZoneJTxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(20, 20, 20)
                        .addComponent(CostPSecJLbl))
                    .addComponent(CostJTxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(OSJLbl)
                    .addComponent(OSJTxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ArchitectJLbl)
                    .addComponent(ArchitectJTxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(23, 23, 23)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ProcJLbl)
                    .addComponent(CountProcJLbl)
                    .addComponent(ProcCountjTxtField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ConfirmjLbl)
                .addContainerGap(81, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void TablejTblFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_TablejTblFocusLost
//        TablejTbl.
        ProcessorsSet();
    }//GEN-LAST:event_TablejTblFocusLost

    private void jScrollPane1FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jScrollPane1FocusLost
        ProcessorsSet();
    }//GEN-LAST:event_jScrollPane1FocusLost

    private void ProcCountjTxtFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_ProcCountjTxtFieldFocusLost
        ProcessorsCountSet();
        FillUpTheTable();
    }//GEN-LAST:event_ProcCountjTxtFieldFocusLost

    private void ProcCountjTxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ProcCountjTxtFieldActionPerformed
        ProcessorsCountSet();
        FillUpTheTable();
    }//GEN-LAST:event_ProcCountjTxtFieldActionPerformed
        
    
    private void HolidayLoadJSldMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_HolidayLoadJSldMouseReleased
        holidayLoadSet();
    }//GEN-LAST:event_HolidayLoadJSldMouseReleased

    private void OffPeakLoadJSldMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_OffPeakLoadJSldMouseReleased
        offPeakLoadSet();
    }//GEN-LAST:event_OffPeakLoadJSldMouseReleased

    private void PeakLoadJSldMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_PeakLoadJSldMouseReleased
        peakLoadSet();
    }//GEN-LAST:event_PeakLoadJSldMouseReleased

    private void ArchitectJTxtFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_ArchitectJTxtFieldFocusLost
        architectureSet();
    }//GEN-LAST:event_ArchitectJTxtFieldFocusLost

    private void OSJTxtFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_OSJTxtFieldFocusLost
        osSet();
    }//GEN-LAST:event_OSJTxtFieldFocusLost

    private void CostJTxtFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_CostJTxtFieldFocusLost
        costPerSecSet();
    }//GEN-LAST:event_CostJTxtFieldFocusLost

    private void TimeZoneJTxtFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_TimeZoneJTxtFieldFocusLost
        timeZoneSet();
    }//GEN-LAST:event_TimeZoneJTxtFieldFocusLost

    private void NameJTxtFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_NameJTxtFieldFocusLost
        nameSet();        
    }//GEN-LAST:event_NameJTxtFieldFocusLost

    /**
     * Nastavi pre Resource (Zdroj) parameter Holiday Load (vytazenie pocas prazdnin)
     */
    private void holidayLoadSet(){    
        if ((HolidayLoadJSld.getValue() >=0) && (HolidayLoadJSld.getValue() < 100.00)){
            Resource.setHolidayLoad(HolidayLoadJSld.getValue()/100.00);            
        } else {
            HolidayLoadJSld.setValue(Double.valueOf(Resource.getHolidayLoad()*100.00).intValue());
            GangstersGrid.showErrorMessage("'Holiday load' must be greater than 0% and lower than 100%.");            
        }
    }
    
    /**
     * Nastavi pre Resource (Zdroj) parameter Off-peak Load (vytazenie mimo spicky) 
     */
    private void offPeakLoadSet(){
        if ((OffPeakLoadJSld.getValue() >=0) && (OffPeakLoadJSld.getValue() < 100.00)){
            Resource.setOffPeakLoad(OffPeakLoadJSld.getValue()/100.00);            
        }else {
            OffPeakLoadJSld.setValue(Double.valueOf(Resource.getOffPeakLoad()*100.00).intValue());
            GangstersGrid.showErrorMessage("'Off-peak load' must be greater than 0% and lower than 100%.");            
        }     
    }
    
    /**
     * Nastavi pre Resource (Zdroj) parameter Peak Load (vytazenie pocas spicky)
     */
    private void peakLoadSet(){
        if ((PeakLoadJSld.getValue() >=0) && (PeakLoadJSld.getValue() < 100.00)){
            Resource.setPeakLoad(PeakLoadJSld.getValue()/100.00);            
        }else {
            PeakLoadJSld.setValue(Double.valueOf(Resource.getPeakLoad()*100.00).intValue());
            GangstersGrid.showErrorMessage("'Peak load' must be greater than 0% and lower than 100%.");
            }                 
    }
         
    /**
     * Nastavi pre Resource (Zdroj) parameter Architecture (architektura)
     */
    private void architectureSet() {
        if (!ArchitectJTxtField.getText().isEmpty()) {
            Resource.setArchitecture(ArchitectJTxtField.getText());
        } else {
            ArchitectJTxtField.setText(Resource.getArchitecture());
            GangstersGrid.showErrorMessage("Architecture must be defined.");
        }                    
    }
    
    private void ArchitectJTxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ArchitectJTxtFieldActionPerformed
        architectureSet();
    }//GEN-LAST:event_ArchitectJTxtFieldActionPerformed

    /**
     * Nastavi pre Resource (Zdroj) parameter Operating System (Operacny System)
     */
    private void osSet() {
        if (!OSJTxtField.getText().isEmpty()) {
            Resource.setOs(OSJTxtField.getText());
        } else {
            OSJTxtField.setText(Resource.getOs());
            GangstersGrid.showErrorMessage("Operation system must be defined.");
        }                    
    }
    
    private void OSJTxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OSJTxtFieldActionPerformed
        osSet();
    }//GEN-LAST:event_OSJTxtFieldActionPerformed

    /**
     * Nastavi pre Resource (Zdroj) parameter Cost per second (Sekundove naklady)
     */    
    private void costPerSecSet() {
        Double CostPerSec;    
        try {
            CostPerSec = Double.valueOf(CostJTxtField.getText());
            if (CostPerSec > 0)  {
                Resource.setCostPerSec(CostPerSec);
            } else GangstersGrid.showErrorMessage("'Cost per second' must be greater than 0."); 
            
        } catch (Exception NumberFormatException) {
            CostJTxtField.setText(Double.valueOf(Resource.getCostPerSec()).toString());
            GangstersGrid.showErrorMessage("'Cost per second' must be a number.");                    
        }
    }
    
    private void CostJTxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CostJTxtFieldActionPerformed
        costPerSecSet();
    }//GEN-LAST:event_CostJTxtFieldActionPerformed

    /**
     * Nastavi pre Resource (Zdroj) parameter Time zone (Casova zona)
     */
    private void timeZoneSet(){
    Double TimeZone;    
        try {
            TimeZone = Double.valueOf(TimeZoneJTxtField.getText());
            if ((TimeZone >= 0) && (TimeZone < 24)) {
                Resource.setTimeZone(TimeZone);
            } else GangstersGrid.showErrorMessage("Time zone must be between 0 and 23s"); 
            
        } catch (Exception NumberFormatException) {
            TimeZoneJTxtField.setText(Double.valueOf(Resource.getTimeZone()).toString());
            GangstersGrid.showErrorMessage("Time zone must be a number.");                    
        }
    }
       
    
    private void TimeZoneJTxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TimeZoneJTxtFieldActionPerformed
        timeZoneSet();
    }//GEN-LAST:event_TimeZoneJTxtFieldActionPerformed

    /**
     * Nastavi pre Resource (Zdroj) parameter Name (Meno)
     */
    private void nameSet() {
        try {
            Resource.setName(NameJTxtField.getText());
        } catch (Exception ex) {
            NameJTxtField.setText(Resource.getName());
            GangstersGrid.showErrorMessage(ex.getMessage());
        }
    }
  
 
    private void NameJTxtFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_NameJTxtFieldActionPerformed
        nameSet();
    }//GEN-LAST:event_NameJTxtFieldActionPerformed
    
    /**
     * Nastavi pre Resource (Zdroj) pocet Processors-count (Pocet procesorov)
     */
    private void ProcessorsCountSet(){
        Integer ProcCount;    
        try {
            ProcCount = Integer.valueOf(ProcCountjTxtField.getText());
            if (ProcCount > 0)  {                
            } else{
                ProcCountjTxtField.setText(Integer.valueOf(TablejTbl.getRowCount()).toString());
                GangstersGrid.showErrorMessage("'Processors-count' must be greater than 0.");               
            }                             
        } catch (Exception NumberFormatException) {
            ProcCountjTxtField.setText(Integer.valueOf(TablejTbl.getRowCount()).toString());
            GangstersGrid.showErrorMessage("'Processors count' must be a number.");                    
        }
    }
    
    /**
     * Nastavi pre Resource (Zdroj) paramter procesorov - Performance (Vykon)
     */
    private void ProcessorsSet(){
        Vector values = new Vector();
        Integer proc_value = null;
        for (int i = 0; i < Integer.valueOf(ProcCountjTxtField.getText()); i++) {        
        /*    values.add(i,TablejTbl.getValueAt(i,1));            
        }                       
        Resource.setProcessors(values);
         */              
            try {                            
                proc_value = (Integer.valueOf(TablejTbl.getValueAt(i,1).toString()));                
                if (proc_value <= 0){
                    TablejTbl.setValueAt(Resource.getProcessors().get(i),i,1);
                    proc_value=Resource.getProcessors().get(i);
                    GangstersGrid.showErrorMessage("'Performance' must be greater than zero.");                            
                }
             } catch (Exception NumberFormatException) {                              
                TablejTbl.setValueAt(Resource.getProcessors().get(i),i,1);
                proc_value=Resource.getProcessors().get(i);
                GangstersGrid.showErrorMessage("'Performance' must be a number.");
            }
            values.addElement(proc_value);            
        }        
        Resource.setProcessors(values);   
        
    }
    
    /**
     * Naplna tabulku s procesormi im odpovedajucimi potrebnymi paramatremi
     */ 
    private void FillUpTheTable(){                
        DefaultTableModel model = (DefaultTableModel)TablejTbl.getModel();       
        Vector row = new Vector();
        Vector data = new Vector();
        Vector columns_identifiers = new Vector();
        Vector values = new Vector();
        row.addElement("");
        columns_identifiers.addElement("Processors");
        columns_identifiers.addElement("Performance");
                     
        model.setColumnIdentifiers(columns_identifiers);         
        model.setRowCount(0);
        model.setRowCount(Integer.valueOf(ProcCountjTxtField.getText()));
        TablejTbl.getColumn("Performance").setCellEditor(TablejTbl.getDefaultEditor(Integer.class));
        TablejTbl.getColumn("Performance").getCellEditor().addCellEditorListener(this);

        for (int i = 0; i < Integer.valueOf(ProcCountjTxtField.getText()); i++) {                       
            TablejTbl.setValueAt("Processor "+(i+1),i,0);                                     
            int newValue;
            if (Resource.getProcessors().size()-i-1 >= 0){ // osterenie poctu prvkov vo vectore
                newValue = Resource.getProcessors().get(i);
            } else {
                newValue = 1;
            }
            TablejTbl.setValueAt(newValue,i,1);
            values.add(newValue);
        }  
        Resource.setProcessors(values);
    }         
    
    /**
     * Nastavi pre Resource (Zdroj) vsetky jeho potrebne parametre
     */
    public void FillUpResourceDetails(){
        nameSet();
        peakLoadSet();
        offPeakLoadSet();
        holidayLoadSet();
        timeZoneSet();
        costPerSecSet();
        osSet();
        architectureSet();
        ProcessorsSet();        
                
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel ArchitectJLbl;
    private javax.swing.JTextField ArchitectJTxtField;
    private javax.swing.JLabel ConfirmjLbl;
    private javax.swing.JTextField CostJTxtField;
    private javax.swing.JLabel CostPSecJLbl;
    private javax.swing.JLabel CountProcJLbl;
    private javax.swing.JLabel HolidayJLbl;
    private javax.swing.JSlider HolidayLoadJSld;
    private javax.swing.JLabel NameJLbl;
    private javax.swing.JTextField NameJTxtField;
    private javax.swing.JLabel OSJLbl;
    private javax.swing.JTextField OSJTxtField;
    private javax.swing.JLabel OffPeakLoadJLbl;
    private javax.swing.JSlider OffPeakLoadJSld;
    private javax.swing.JLabel PeakLoadJLbl;
    private javax.swing.JSlider PeakLoadJSld;
    private javax.swing.JTextField ProcCountjTxtField;
    private javax.swing.JLabel ProcJLbl;
    private javax.swing.JTable TablejTbl;
    private javax.swing.JLabel TimeZoneJLbl;
    private javax.swing.JTextField TimeZoneJTxtField;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

    public void setObject(Object o) {               
        Resource = ((GridResource)o);        
        NameJTxtField.setText(Resource.getName());
        PeakLoadJSld.setValue(Double.valueOf(Resource.getPeakLoad()*100).intValue());
        OffPeakLoadJSld.setValue(Double.valueOf(Resource.getOffPeakLoad()*100).intValue());
        HolidayLoadJSld.setValue(Double.valueOf(Resource.getHolidayLoad()*100).intValue());
        TimeZoneJTxtField.setText(Double.valueOf(Resource.getTimeZone()).toString());
        CostJTxtField.setText(Double.valueOf(Resource.getCostPerSec()).toString());
        OSJTxtField.setText(Resource.getOs());
        ArchitectJTxtField.setText(Resource.getArchitecture());        
        ProcCountjTxtField.setText(Integer.valueOf(Resource.getProcessors().size()).toString());
        System.out.println("Default processors size : " + Resource.getProcessors().size());
        FillUpTheTable();

        
    }

    public void saveObjectValues() {
        if (Resource != null){
            FillUpResourceDetails();
        }
    }

    public void editingStopped(ChangeEvent e) {
        System.out.println("editingStopped");
        ProcessorsSet();
    }

    public void editingCanceled(ChangeEvent e) {
        System.out.println("editingCanceled");
    }
    
}
